package app.ui;

import java.io.IOException;
import java.util.List;

import database.local.Business;
import database.local.CheckIn;
import database.local.QueryData;

import android.os.AsyncTask;
import android.util.Log;
import app.ui.BusinessListArrayAdapter;
import app.ui.PreferencesActivity;

public class BusinessViewSyncronizer {
	private Business business;
	private DealsListView context;

	public BusinessViewSyncronizer(DealsListView context) {
		this.context = context;
	}


	public class MyAsyncSyncronyser extends AsyncTask<String, Void, Integer> {
		private List<CheckIn> checkin_list;

		protected Integer doInBackground(String... params) {
			Log.w("Business", "Started sync with BusinessSyncronyser");
			QueryData query = new QueryData();
			checkin_list = query.getCheckIns(business);
			if (checkin_list == null)
				return 0;

			Log.w("Business", "Finished sync with BusinessSyncronyser");
			return 1;
		}

		protected void onPostExecute(Integer result) {
			Log.i("Business",
					"Done getting data, found " + checkin_list.size()
							+ " checkins");
			
			for (CheckIn ch:checkin_list){
				BitmapSyncronizer cs = new BitmapSyncronizer(context);
				cs.getBitmap(ch.getPic(), ch.getFacebook_link());
			}
		}

	}

	

	public void sync(Business business) {
		MyAsyncSyncronyser inst = new MyAsyncSyncronyser();
		this.business = business;
		try {
			inst.execute();
		} catch (Exception e) {
			Log.e("DEBUGTAG", "Problem with sycronization", e);
		}
	}
	

}
